package com.cvtt.common;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;


public class AlarmUtil {

	public static AlarmManager getAlarmManager(Context ctx) {
		return (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
	}

	public static void alarm(Context ctx, int renew_time, Class<?> cls) {
		if (ctx == null)
			return;
		Intent intent = new Intent(ctx, cls);
		PendingIntent sender = PendingIntent.getBroadcast(ctx, 0, intent, 0);
		AlarmManager am = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
		am.cancel(sender);
		if (renew_time > 0) {
			if (Util.isMIUI()||Util.isGT19228()) {
				am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + renew_time * 1000, sender);
			}
			else {
				am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + renew_time * 1000, sender);
			}
		}
	}
}